package com.ruoyi.syf.handler.deleteChain.chainHandler;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.syf.domain.RiskEvaluationAccidentDetail;
import com.ruoyi.syf.handler.deleteChain.DeleteChainHandler;
import com.ruoyi.syf.service.IRiskEvaluationAccidentDetailService;
import com.ruoyi.syf.service.IRiskEvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EvaluationHandler extends DeleteChainHandler {

    @Autowired
    private IRiskEvaluationService evaluationService;
    @Autowired
    private IRiskEvaluationAccidentDetailService detailService;
//    @Autowired
//    private IRiskMeasureService measureService;

    @Override
    public void handleDelete(List<Long> ids) {
        //删除风险分析
        evaluationService.deleteRiskEvaluationByIds(ids.toArray(new Long[0]));
        if (nextHandler != null) {
            //查询风险分析详情
            List<RiskEvaluationAccidentDetail> list = detailService.list(new LambdaQueryWrapper<RiskEvaluationAccidentDetail>()
                    .in(RiskEvaluationAccidentDetail::getEvaluationId, ids));
            if (!list.isEmpty()){
                nextHandler.handleDelete(list.stream()
                        .map(RiskEvaluationAccidentDetail::getId).collect(Collectors.toList()));
            }
        }

//        //查询风险分析详情
//        List<RiskEvaluationAccidentDetail> detailList = detailService.list(new LambdaQueryWrapper<RiskEvaluationAccidentDetail>()
//                .in(RiskEvaluationAccidentDetail::getEvaluationId, ids));
//        List<Long> detailIds = detailList.stream()
//                .map(RiskEvaluationAccidentDetail::getId).collect(Collectors.toList());
//        //删除风险分析
//        evaluationService.deleteRiskEvaluationByIds(ids.toArray(new Long[0]));
//        if (nextHandler != null) {
//            //查询管控措施
//            List<RiskMeasure> list = measureService.list(new LambdaQueryWrapper<RiskMeasure>().in(RiskMeasure::getDetailId, detailIds));
//            if (!list.isEmpty()){
//                nextHandler.handleDelete(list.stream().map(RiskMeasure::getId).collect(Collectors.toList()));
//            }
//        }
    }

}
